<template>
  <header class="header">
    <h1>todos</h1>
    <input
      class="new-todo"
      placeholder="What needs to be done?"
      autofocus
      v-model.trim="todoName"
      @keyup.enter="add"
    />
  </header>
</template>

<script>
import { mapMutations } from 'vuex'
export default {
  name: 'TodoHeader',
  data() {
    return {
      todoName: '',
    }
  },
  methods: {
    ...mapMutations('todoMvcModel',['ADDTODO']),
    // 添加一个新任务的委托
    add() {
      if (!this.todoName) {
        this.todoName = ''
        return alert('请输入正确格式的任务！')
      }
      this.ADDTODO(this.todoName)
      this.todoName = ''
    },
  },
}
</script>

<style></style>
